<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/assets/images/favicon.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/assets/images/favicon.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="//cdn.bootcdn.net/ajax/libs/font-awesome/5.15.1/css/all.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"zhengpj.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="滑动窗口就是双指针的一种技巧，运用的就是双指针，但是仅能维持一个指针移动，另一个指针呆着不动。 当一个指针维持不动，另一个指针移动时，两个指针之间的部分就是一个窗口，这个窗口是不断的扩大和缩小的，直到末尾或找到结果。">
<meta property="og:type" content="article">
<meta property="og:title" content="算法思维--滑动窗口">
<meta property="og:url" content="http://zhengpj.gitee.io/2020/11/22/%E7%AE%97%E6%B3%95%E6%80%9D%E7%BB%B4-%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3/index.html">
<meta property="og:site_name" content="浪荡&amp;不羁">
<meta property="og:description" content="滑动窗口就是双指针的一种技巧，运用的就是双指针，但是仅能维持一个指针移动，另一个指针呆着不动。 当一个指针维持不动，另一个指针移动时，两个指针之间的部分就是一个窗口，这个窗口是不断的扩大和缩小的，直到末尾或找到结果。">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2020-11-22T07:30:24.000Z">
<meta property="article:modified_time" content="2022-04-07T08:20:04.392Z">
<meta property="article:author" content="zhengpj">
<meta property="article:tag" content="leetcode">
<meta property="article:tag" content="algorithm">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://zhengpj.gitee.io/2020/11/22/%E7%AE%97%E6%B3%95%E6%80%9D%E7%BB%B4-%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'en'
  };
</script>

  <title>算法思维--滑动窗口 | 浪荡&不羁</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">浪荡&不羁</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">厚积薄发，厚德载物</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>About</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags" rel="section"><i class="fa fa-tags fa-fw"></i>Tags</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>Categories</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/zhengpj95" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="http://zhengpj.gitee.io/2020/11/22/%E7%AE%97%E6%B3%95%E6%80%9D%E7%BB%B4-%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/assets/images/avatar.jpg">
      <meta itemprop="name" content="zhengpj">
      <meta itemprop="description" content="游戏开发，热爱JavaScript, nodejs">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="浪荡&不羁">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          算法思维--滑动窗口
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2020-11-22 15:30:24" itemprop="dateCreated datePublished" datetime="2020-11-22T15:30:24+08:00">2020-11-22</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2022-04-07 16:20:04" itemprop="dateModified" datetime="2022-04-07T16:20:04+08:00">2022-04-07</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Algorithm/" itemprop="url" rel="index"><span itemprop="name">Algorithm</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>滑动窗口就是双指针的一种技巧，运用的就是双指针，但是仅能维持一个指针移动，另一个指针呆着不动。</p>
<p>当一个指针维持不动，另一个指针移动时，两个指针之间的部分就是一个窗口，这个窗口是不断的扩大和缩小的，直到末尾或找到结果。</p>
<a id="more"></a>

<h2 id="1-思路"><a href="#1-思路" class="headerlink" title="1. 思路"></a>1. 思路</h2><p>简单思路就是：</p>
<ol>
<li><em>right</em> 指针不断向右扩张，直到满足限制的条件</li>
<li>开始让 <em>left</em> 指针向右移动，直到不满足限制的条件，此时重回第一步移动 <em>right</em> 指针</li>
<li>反复操作步骤1、2，直到右指针到末尾或退出循环</li>
</ol>
<p>对于窗口移动，不是很难理解的事情，难点在于窗口扩大或缩小过程中，如何判断窗口内数据满足了条件。<br>如在做 LeetCode 的 76 题 Minimum Window Substring 时，我使用的是将窗口内的子字符串变成 Map，再去匹配，这样子就有两个 Map 要去匹配了，又是一个 for 循环判断，这样会耗时很大，用这种方法提交 LeetCode，直接判了 Time Limit Exceeded。</p>
<h2 id="2-套路模板"><a href="#2-套路模板" class="headerlink" title="2. 套路模板"></a>2. 套路模板</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> left = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">let</span> right = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">let</span> <span class="built_in">window</span>;</span><br><span class="line"><span class="keyword">while</span> (right satisfy conditions) &#123;</span><br><span class="line">  <span class="comment">// 扩大窗口</span></span><br><span class="line">  <span class="built_in">window</span>.add(xxx);</span><br><span class="line">  right++;</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 出现满足条件的情况，开始缩小窗口</span></span><br><span class="line">  <span class="keyword">while</span> or <span class="keyword">if</span> (<span class="built_in">window</span> meet conditions) &#123;</span><br><span class="line">    <span class="built_in">window</span>.remove(xxx);</span><br><span class="line">    left++;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>窗口大小：</strong> 分为固定和不固定的情况</p>
<ol>
<li>不固定大小：<ul>
<li><em>right</em> 指针开始右移，直到出现满足条件的情况</li>
<li>然后 <em>left</em> 开始右移，直到出现不满足条件的情况</li>
<li>不断重复上面的步骤，直到 <em>right</em> 指针到末尾</li>
</ul>
</li>
<li>固定大小：<ul>
<li>先开始移动 <em>right</em> 指针，直到窗口大小等于固定大小时</li>
<li>当窗口大小等于固定大小时，就是要判断条件的时候</li>
<li>然后开始同步移动 <em>right</em>、<em>left</em> 指针</li>
<li>不断重复上面的步骤，直到 <em>right</em> 指针到末尾</li>
</ul>
</li>
</ol>
<h2 id="3-以题讲解"><a href="#3-以题讲解" class="headerlink" title="3. 以题讲解"></a>3. 以题讲解</h2><p>我们以 LeetCode 的 <em>76. Minimum Window Substring</em> 题目来讲解 <strong>滑动窗口</strong> 的思路。</p>
<figure class="highlight text"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Given two strings s and t, return the minimum window in s which will contain all the characters in t.</span><br><span class="line">If there is no such window in s that covers all characters in t, return the empty string &quot;&quot;.</span><br><span class="line"></span><br><span class="line">Note that If there is such a window,</span><br><span class="line">it is guaranteed that there will always be only one unique minimum window in s.</span><br><span class="line"></span><br><span class="line">Constraints: 1 &lt;= s.length, t.length &lt;= 10^5; s and t consist of English letters.</span><br></pre></td></tr></table></figure>

<p>给定两个字符串 <code>s</code>, <code>t</code>，我们需要在 <code>s</code> 中超出包含 <code>t</code> 的全部字符的最小子串，并返回此字符串。</p>
<p>题目中已经保证如果 <code>s</code> 中存在这样的子串，它是唯一的答案；题目中可以不保证这样唯一的子串，我们在代码中只返回第一个出现的字串即可。</p>
<p>以 <code>s = &quot;ADOBECODEBANC&quot;, t = &quot;ABC&quot;</code> 为例，我们定义两个指针 <em>left</em>, <em>right</em>，其都指向字符串 s 的第一个字母。</p>
<p>1、<em>right</em> 指针不断向右移动，知道出现了子串中满足 <code>t</code>，此时子串是 <code>ADOBEC</code>，记录结果，此时指针未到末尾，还需继续操作；</p>
<p>2、开始移动 <em>left</em> 指针，其移动到下标 1 时，left 和 right 之间的子串已经不满足 <code>t</code>，此时 <em>right</em> 指针要开始右移；</p>
<p>3、当出现字串 <code>DOBECODEBA</code> 时，又满足的 <code>t</code> ，此时就需要移动 <em>left</em> 指针并与已记录的结果判断，是否比已记录的结果更小；在操作过程中，结果值不断变化，最后更新为 <code>CODEBA</code>；<em>left</em> 指针再往右移动，不满足条件；</p>
<p>4、开始 <em>right</em> 右移，直到其到达末尾，此时出现子串 <code>ODEBANC</code>，满足 <code>t</code> 情况；需要开始移动 <em>left</em> 指针，最后得到结果值 <code>BANC</code> 的最短字串。</p>
<p>在上述过程中，思路很简单易懂，但是主要关键点就在于 <strong>如何判断 left 和 right 之间的子串是满足 t 且是最小的子串长度呢</strong>。</p>
<p>思路一：我们可使用两个 map 来记录 <code>t</code> 和 <em>子串</em>，每移动一次 right 指针，我们就判断两个map的关系。但是这样的操作的时间复杂度达到 n*m (n=s.length, m = t.length)；显然这样的操作是可以的，但是会出现超时情况。<br>思路二：我们使用一个变量来记录子串是否满足 <code>t</code> 的每种字母及其数量。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> valid = <span class="number">0</span>; <span class="comment">//t 中字母的种类</span></span><br><span class="line"><span class="keyword">while</span> (right &lt; s.length) &#123;</span><br><span class="line">  <span class="keyword">let</span> char = s[right];</span><br><span class="line">  <span class="comment">// 当前字符在t中且数量相同</span></span><br><span class="line">  <span class="keyword">if</span> (char 在 t &amp;&amp; char 的数量等于在 t 中数量) &#123;</span><br><span class="line">    valid++;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 出现了满足 t 的子串</span></span><br><span class="line">  <span class="keyword">while</span> (valid == t 的种类) &#123;</span><br><span class="line">    <span class="comment">// 更新结果</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 缩小窗口</span></span><br><span class="line">    <span class="keyword">let</span> removeChar = s[left++]</span><br><span class="line">    <span class="keyword">if</span> (removeChar 在 t) &#123;</span><br><span class="line">      <span class="comment">// 更新valid--</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  right++;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>完整代码附下：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> minWindow = (s, t) &#123;</span><br><span class="line">  <span class="keyword">if</span> (!t || !t.length || !s || !s.length || s.length &lt; t.length)</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&#x27;&#x27;</span>;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">let</span> needMap = <span class="keyword">new</span> <span class="built_in">Map</span>();</span><br><span class="line">  <span class="keyword">let</span> windowMap = <span class="keyword">new</span> <span class="built_in">Map</span>();</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; t.length; i++) &#123;</span><br><span class="line">    needMap.set(t[i], needMap.has(t[i]) ? needMap.get(t[i]) + <span class="number">1</span> : <span class="number">1</span>);</span><br><span class="line">    windowMap.set(t[i], <span class="number">0</span>);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">let</span> res = <span class="literal">null</span>;</span><br><span class="line">  <span class="keyword">let</span> valid = <span class="number">0</span>; <span class="comment">//t的字母数量</span></span><br><span class="line">  <span class="keyword">let</span> left = <span class="number">0</span>,</span><br><span class="line">      right = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 右指针未到末尾</span></span><br><span class="line">  <span class="keyword">while</span> (right &lt; s.length) &#123;</span><br><span class="line">    <span class="comment">// 扩张窗口</span></span><br><span class="line">    <span class="keyword">let</span> addChar = s[right];</span><br><span class="line">    right++;</span><br><span class="line">    <span class="keyword">if</span> (needMap.has(addChar)) &#123;</span><br><span class="line">      windowMap.set(addChar, windowMap.get(addChar) + <span class="number">1</span>);</span><br><span class="line">      <span class="keyword">if</span> (needMap.get(addChar) === windowMap.get(addChar)) valid++;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 有满足条件的子字符串，开始收缩窗口，寻找最小字符串</span></span><br><span class="line">    <span class="keyword">while</span> (valid === needMap.size) &#123;</span><br><span class="line">      <span class="keyword">let</span> str = s.slice(left, right);</span><br><span class="line">      <span class="keyword">if</span> (res === <span class="literal">null</span> || str.length &lt; res.length) res = str;</span><br><span class="line"></span><br><span class="line">      <span class="keyword">let</span> removeChar = s[left];</span><br><span class="line">      left++;</span><br><span class="line"></span><br><span class="line">      <span class="comment">// 这一步刚好和扩张窗口对称</span></span><br><span class="line">      <span class="keyword">if</span> (needMap.has(removeChar)) &#123;</span><br><span class="line">        <span class="keyword">if</span> (needMap.get(removeChar) === windowMap.get(removeChar)) valid--;</span><br><span class="line">        windowMap.set(removeChar, windowMap.get(removeChar) - <span class="number">1</span>);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> res === <span class="literal">null</span> ? <span class="string">&#x27;&#x27;</span> : res;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h2 id="4-总结"><a href="#4-总结" class="headerlink" title="4. 总结"></a>4. 总结</h2><p>滑动窗口，最重要的是 <strong>判断什么时候开始右指针移动，什么时候开始左指针移动，什么时候更新结果</strong>。滑动窗口问题，万变不离其宗，注意窗口的边界和窗口的内容即可。</p>
<p>（写完了，但是质量不高。仍需努力呀，争取写出越来越优秀的文章。）</p>

    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>Post author:  </strong>zhengpj
  </li>
  <li class="post-copyright-link">
    <strong>Post link: </strong>
    <a href="http://zhengpj.gitee.io/2020/11/22/%E7%AE%97%E6%B3%95%E6%80%9D%E7%BB%B4-%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3/" title="算法思维--滑动窗口">http://zhengpj.gitee.io/2020/11/22/算法思维-滑动窗口/</a>
  </li>
  <li class="post-copyright-license">
    <strong>Copyright Notice:  </strong>All articles in this blog are licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> unless stating additionally.
  </li>
</ul>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/leetcode/" rel="tag"><i class="fa fa-tag"></i> leetcode</a>
              <a href="/tags/algorithm/" rel="tag"><i class="fa fa-tag"></i> algorithm</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/11/21/%E7%AE%97%E6%B3%95%E6%80%9D%E7%BB%B4-%E5%89%8D%E7%BC%80%E5%92%8C%E6%8A%80%E5%B7%A7/" rel="prev" title="算法思维--前缀和技巧">
      <i class="fa fa-chevron-left"></i> 算法思维--前缀和技巧
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/11/24/youtube-dl-%E4%BD%BF%E7%94%A8%E5%B0%8F%E8%AE%B0/" rel="next" title="youtube-dl 使用小记">
      youtube-dl 使用小记 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%80%9D%E8%B7%AF"><span class="nav-number">1.</span> <span class="nav-text">1. 思路</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%A5%97%E8%B7%AF%E6%A8%A1%E6%9D%BF"><span class="nav-number">2.</span> <span class="nav-text">2. 套路模板</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E4%BB%A5%E9%A2%98%E8%AE%B2%E8%A7%A3"><span class="nav-number">3.</span> <span class="nav-text">3. 以题讲解</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E6%80%BB%E7%BB%93"><span class="nav-number">4.</span> <span class="nav-text">4. 总结</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="zhengpj"
      src="/assets/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">zhengpj</p>
  <div class="site-description" itemprop="description">游戏开发，热爱JavaScript, nodejs</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">15</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags">
          
        <span class="site-state-item-count">12</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/zhengpj95" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zhengpj95" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/zhengpj" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;zhengpj" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>Gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:zheng-598@qq.com" title="E-Mail → mailto:zheng-598@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">zhengpj</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a>
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
